﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using IRepository;

namespace ConcreteService
{
    public class UserInfoService : CommonService
    {
        public Models.UserInfo Login(string loginValue, string password)
        {
            if (loginValue == null || password == null)
                throw new Exception("UserInfoService.Login :: parameter is null");

            IUserInfoRepository userService = ServiceFactory.CreateInstance<IUserInfoRepository>();

            var user = userService.Login(loginValue, password);
            if (user != null)
                LogUtil.Create(user.UserNo.ToString(), EventType.Login, user.NickName, "Login");

            return user;
        }
        public bool IsUserExist(string userName)
        {
            if (userName == null)
                throw new Exception("UserInfoService.IsUserExist :: parameter is null");

            IUserInfoRepository userService = ServiceFactory.CreateInstance<IUserInfoRepository>();
            return userService.IsUserExist(userName);
        }

        public void UpdatePassword(string userName, string password)
        {
            if (userName == null)
                throw new Exception("UserInfoService.IsUserExist :: parameter is null");

            IUserInfoRepository userService = ServiceFactory.CreateInstance<IUserInfoRepository>();
            userService.UpdatePassword(userName, password);
            LogUtil.Create(userName, EventType.UpdatePassword, "update Password", "update to" + password);
        }

        public IList<IDictionary<string, string>> ListAgent()
        {
            IUserInfoRepository userService = ServiceFactory.CreateInstance<IUserInfoRepository>();
            return userService.ListAgent();
        }

    }
}
